<template>
  <el-config-provider :locale="getGlobalI18n" :size="appStore.size">
    <router-view />
  </el-config-provider>
</template>

<script setup lang="ts">
import useSettingsStore from '@/store/modules/settings';
import { handleThemeStyle } from '@/utils/theme';
import useAppStore from '@/store/modules/app';
import { useI18n } from 'vue-i18n';
import { useThemeConfig } from '@/store/themeConfig';
import { Local, Session } from '@/utils/storage';

// 定义变量内容
const { messages, locale } = useI18n();
const storesThemeConfig = useThemeConfig();
const { themeConfig } = storeToRefs(storesThemeConfig);

const appStore = useAppStore();

// 获取全局 i18n
const getGlobalI18n = computed(() => {
  return messages.value[locale.value];
});


onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme);
    console.log('APP Local.get(\'themeConfig\')', Local.get('themeConfig'))
    // 获取缓存中的布局配置
    if (Local.get('themeConfig')) {
      let lang = Local.get('themeConfig').globalI18n;
      storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
      locale.value = lang;
      // document.documentElement.style.cssText = Local.get('themeConfigStyle');
    }

  });
});
</script>
